package com.he.controller;

import com.he.entity.Book;
import com.he.entity.BookCategory;
import com.he.service.BookService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/book")
public class BookController {

    @Resource
    private BookService bookService;

    @GetMapping("/hello")
    public String hello(){
        return "Hello Java";
    }

    @GetMapping("/selectBookList")
    public List<Book> selectBookList(){
        List<Book> bookList = bookService.selectBookList();
        System.out.println("bookList = " + bookList.toString());
        return  bookList;
    }

    //方法1 使用MySQL的关键字 limit （当前页-1）*每页记录数, 每页记录数
    @GetMapping("selectBookPage1")
    public List<Book> selectBookPage1(int pageNum, int pageSize){
        List<Book> bookList = bookService.selectBookPage1(pageNum, pageSize);
        return  bookList;
    }

    //方法2 PageHelper  引入依赖，配置文件配置
    @GetMapping("selectBookPage2")
    public List<Book> selectBookPage2(int pageNum, int pageSize){
        List<Book> bookList = bookService.selectBookPage2(pageNum, pageSize);
        return  bookList;
    }

    //方法3 Mybatis-plus自带方法
    @GetMapping("selectBookPage3")
    public List<Book> selectBookPage3(int pageNum, int pageSize){
        List<Book> bookList = bookService.selectBookPage3(pageNum, pageSize);
        return  bookList;
    }

    @GetMapping("/selectBookCategoryList")
    public List<BookCategory> selectBookCategoryList(){
        return bookService.selectBookCategoryList();
    }

}
